<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ include file="/WEB-INF/jsp/inc/taglib.jsp" %>
<%-- 设置URL参数 --%>
<c:set var="queryURL" value="${baseURL}/${domainObjectName?uncap_first}" />
<c:set var="viewURL" value="${baseURL}/${domainObjectName?uncap_first}/{0}" />
<c:set var="createURL" value="${baseURL}/${domainObjectName?uncap_first}/create" />
<c:set var="updateURL" value="${baseURL}/${domainObjectName?uncap_first}/{0}/update" />
<c:set var="deleteURL" value="${baseURL}/${domainObjectName?uncap_first}/{0}/delete" />

<c:set var="searchPage" value="query.jsp" />
<c:set var="modelMessageKey" value="${domainObjectName?uncap_first}" />
<%-- 权限设置 --%>
<c:set var="createPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:create" />
<c:set var="updatePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:update" />
<c:set var="deletePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:delete" />
<c:set var="viewPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:view" />

<!DOCTYPE html>
<html>
<head>
<title><fmt:message key="${domainObjectName?uncap_first }" /></title>
<%@ include file="/WEB-INF/jsp/inc/inc-head.jsp"%>
<%@ include file="/WEB-INF/jsp/inc/inc-css.jsp"%>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<jsp:include page="${r'${searchPage }' }" />
	</div>
	<div data-options="region:'center',fit:false,border:false">
		<table id="dataGrid" data-options="fit:true,border:false"></table>
	</div>
	<div data-options="region:'east',fit:false,border:false,split:true" class="btns">
		<ul class="btns">
			<shiro:hasPermission name="${r'${viewPermission}'}">
			<li><a href="javascript:void(0);" class="btn btn-default" role="button" onclick="query()"><fmt:message key="global.button.query"/></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="${r'${createPermission}'}">
			<li><a href="javascript:void(0);" class="btn btn-default" role="button" onclick="createModel();"><fmt:message key="global.button.add"/></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="${r'${updatePermission}'}">
			<li><a href="javascript:void(0);" class="btn btn-default" role="button" onclick="selectModel();"><fmt:message key="global.button.select"/></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="${r'${deletePermission}'}">
			<li><a href="javascript:void(0);" class="btn btn-default" role="button" onclick="deleteModel();"><fmt:message key="global.button.delete"/></a></li>
			</shiro:hasPermission>
		</ul>
	</div>
</div>
</body>
</html>
<%@ include file="/WEB-INF/jsp/inc/inc.jsp"%>
<%@ include file="/WEB-INF/jsp/common/messager.jsp" %>
<script type="text/javascript">
var queryParams={"first":true};
var columns = [
<#assign flag = true />
<#list table.allColumns as column>
	<#if !(primaryKeyColumns?seq_contains(column))>
		<#if flag >
			<#assign flag=false />
 {width : "100",align : "left", halign : "center", valign : 'middle', sortable : true, title : "<fmt:message key='${domainObjectName?uncap_first}.${column.javaProperty}'/>",field : "${column.javaProperty}"}
		<#else />
,{width : "100",align : "left", halign : "center", valign : 'middle', sortable : true, title : "<fmt:message key='${domainObjectName?uncap_first}.${column.javaProperty}'/>",field : "${column.javaProperty}"}
		</#if>	
	</#if>
</#list>
	];
</script>
<script type="text/javascript">
<shiro:hasPermission name="${r'${viewPermission}'}">
$(function() {
	$('#dataGrid').bootstrapTable({
		sidePagination : 'server', queryParamsType : 'other',
		cache : false, striped : true, pagination : true, clickToSelect : true,
		search : false, showColumns : false, showRefresh : false, minimumCountColumns : 2,
		contentType : 'application/x-www-form-urlencoded', method : 'post',
		queryParams : function(params){
			params = $.extend(params, {page:params.pageNumber,rows:params.pageSize},$("#fromData").serializeObject());
			return params;
		},
		url : '${r'${pageContext.request.contextPath}' }${r'${queryURL }' }',
		pageSize : 10, pageList : [ 10, 25, 50],
		onDblClickRow : function(index,row){
			if(selectModel){selectModel(row.${primaryKeyColumns[0].javaProperty });}
		},
		onBeforeLoad : function(row, param) {
		},
		onLoadSuccess : function(row, data) {
		}
	});
});
function query(){
	$('#dataGrid').bootstrapTable('refresh')
}
</shiro:hasPermission>
</script>
<script type="text/javascript">
var selectModel,createModel,updateModel,deleteModel,viewModel;
selectModel = function(id){
	if(updateModel)
		updateModel(id);
	else if(viewModel)
		viewModel(id);
}
<shiro:hasPermission name="${r'${createPermission}'}">
createModel = function() {
	parent.changeURL("${r'${pageContext.request.contextPath}' }${r'${createURL}' }");
	//window.location.href="${r'${pageContext.request.contextPath}' }${r'${createURL}' }";
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${viewPermission}'}">
viewModel = function(id) {
	if(!id){
		var rows = $('#dataGrid').bootstrapTable('getSelections');
		if(!rows.length){
			layer.msg($.formatString('<fmt:message key="global.show.message.select"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), {skin: 'layui-layer-warn'}); 
			return;
		}
		id = row[0].${primaryKeyColumns[0].javaProperty };
	}
	parent.changeURL($.formatString("${r'${pageContext.request.contextPath}' }${r'${viewURL}' }",id));
	//window.location.href=$.formatString("${r'${pageContext.request.contextPath}' }${r'${viewURL}' }",id);
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${updatePermission}'}">
updateModel = function(id) {
	if(!id){
		var rows = $('#dataGrid').bootstrapTable('getSelected');
		if(!rows.length){
			layer.msg($.formatString('<fmt:message key="global.show.message.select"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), {skin: 'layui-layer-warn'}); 
			return;
		}
		id = row[0].${primaryKeyColumns[0].javaProperty };
	}
	parent.changeURL($.formatString("${r'${pageContext.request.contextPath}' }${r'${updateURL}' }",id));
	//window.location.href=$.formatString("${r'${pageContext.request.contextPath}' }${r'${updateURL}' }",id);
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${deletePermission}'}">
deleteModel = function(id) {
	if(!id){
		var rows = $('#dataGrid').bootstrapTable('getSelected');
		if(!rows.length){
			$.easyui.messager.show("<fmt:message key="global.show.title"/>", $.formatString('<fmt:message key="global.show.message.delete"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), "info", "topCenter",2000);
			return;
		}
		id = rows[0].${primaryKeyColumns[0].javaProperty };
	}
	$.messager.confirm('<fmt:message key="global.confirm.title"/>', $.formatString('<fmt:message key="global.confirm.message"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), function(r) {
		if (r) {
			$.easyui.messager.progress("<fmt:message key="global.progress.tltle"/>","<fmt:message key="global.progress.loading.text"/>");
			$.post('${r'${pageContext.request.contextPath}' }${r'${deleteURL}' }', {
				id : id
			}, function(data) {
				if (data.success) {
					success();dataGrid.datagrid('reload');
				}else{error();}
			}, 'json');
		}
	});
	layer.confirm($.formatString('<fmt:message key="global.confirm.message"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), {icon: 3, title:'<fmt:message key="global.confirm.title"/>'}, function(index){
		parent.changeURL($.formatString("${r'${pageContext.request.contextPath}' }${r'${deleteURL}' }",id));
		//window.location.href=$.formatString('${r'${pageContext.request.contextPath}' }${r'${deleteURL}' }',id);
	});
};
</shiro:hasPermission>
</script>